package com.tian.earth.utils

import android.content.Context
import android.content.SharedPreferences
import com.tian.earth.constant.PreferenceConstants

/**
 * @author tiansongtao, Email:769001510@qq.com
 * @date 19-6-13 下午5:05
 */
class PreferencesUtil private constructor(){

    private lateinit var preferences: SharedPreferences
    companion object {
        val INSTANCE = Holder.single
    }

    private object Holder{
        val single = PreferencesUtil()
    }

    fun init(context: Context) {
        preferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES_NAME,
            Context.MODE_PRIVATE)
    }

    fun putBooleanValue(key: String, result: Boolean): Boolean {
        var edit = preferences.edit()
        edit.putBoolean(key, result)
        return  edit.commit()
    }

    fun getBooleanValue(key: String): Boolean {
        return preferences.getBoolean(key, false)
    }


    fun putStringValue(key: String, result: String): Boolean {
        var edit = preferences.edit()
        edit.putString(key, result)
        return edit.commit()
    }

    fun getStringValue(key: String): String {
        return preferences.getString(key, "")
    }

    fun putIntValue(key: String, result: Int): Boolean {
        var edit = preferences.edit()
        edit.putInt(key, result)
        return edit.commit()
    }

    fun getIntValue(key: String): Int {
        return preferences.getInt(key, -1)
    }





}